<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        var nums = [11, 11,9, 2, 8, 12, 5, 3,3,5,9,2,11, 19, 40, 6, 17,38];

        // 数组.push(数据);
        // []
        //  元素是否不在目标数组中存在  
        // 数组.indexOf(元素) == -1  说明元素不在数组中 
        var newarr = [];

        // 遍历原数组 
        for(var i=0;i<nums.length;i++){
            // i是下标
            if(newarr.indexOf(nums[i]) == -1){
                newarr.push(nums[i]); 
            }
        }

        console.log(newarr)


    </script>
</body>
</html>